library(tidyverse)
library(tidylog)

#GET CROSS-SECTIONAL DATA
MPcs <- read_csv("data/analysis/MP_cs_all.csv")

#GET CROSS-SECTIONAL POSITIONS
MPcs_pos <- read_csv("data/output/MP_posdays.csv")

MPcs <- left_join(MPcs, MPcs_pos, by = "about")

MPcs <- MPcs %>%
  replace_na(list(minister = 0,
                  `opposition whip`=0,
                  `shadow minister`=0,
                  `small party spokesperson`=0,
                  `small party whip`=0,
                  `small party whip and small party spokesperson`=0,
                  `speaker`=0,
                  whip=0,
                  `whip and minister`=0))


resultsbes17 <- readRDS("data/output/elec_results17_bes.RDS")
resultsbes17$constituency_name[resultsbes17$constituency_name=="St Austell and Newquay"] <- "St. Austell and Newquay"
resultsbes17$constituency_name[resultsbes17$constituency_name=="St Helens South and Whiston"] <- "St. Helens South and Whiston"
resultsbes17$constituency_name[resultsbes17$constituency_name=="St Helens North"] <- "St. Helens North"
resultsbes17$constituency_name[resultsbes17$constituency_name=="Holborn and St Pancras"] <- "Holborn and St. Pancras"
resultsbes17$constituency_name[resultsbes17$constituency_name=="St Ives"] <- "St. Ives"
resultsbes17$constituency_name[resultsbes17$constituency_name=="Fermanagh and South Tyrone"] <- "Fermanagh & South Tyrone"
resultsbes17$constituency_name[resultsbes17$constituency_name=="Ynys Môn"] <- "Ynys Mon"
resultsbes17$constituency_name[resultsbes17$constituency_name=="Weston-super-Mare"] <- "Weston-Super-Mare"
resultsbes17$constituency_name[resultsbes17$constituency_name=="Newry and Armagh"] <- "Newry & Armagh"
resultsbes17$constituency_name[resultsbes17$constituency_name=="Bury St Edmunds"] <- "Bury St. Edmunds"

MPcs_add_elec <- left_join(MPcs, resultsbes17, by = c("constituency_name"))

write_csv(MPcs_add_elec, "data/analysis/MP_cs_all.csv")
